package com.czh.mail.service.impl;

import com.czh.mail.service.IMailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
public class MailServiceImpl implements IMailService {

    @Autowired
    JavaMailSender mailSender;
    @Value("${spring.mail.username}")
    String from;

    @Override
    public void sendMail( String to, String subject, String context) {

        SimpleMailMessage mailMessage = new SimpleMailMessage();
        mailMessage.setFrom(from);
        mailMessage.setTo(to);
        mailMessage.setSubject(subject);
        mailMessage.setCc(from);
        mailMessage.setText(context);

        mailSender.send(mailMessage);
    }
}
